package sample;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class MyService {

	@PersistenceContext(unitName="sample")
	private EntityManager em;

	public String greet(){
		long count = (Long)em.createQuery("SELECT COUNT(g) FROM Greet g").getSingleResult();

		Greet g = new Greet();
		g.setId(count + 1L);
		g.setText("hello " + g.getId() + "th.");
		em.persist(g);

		return g.getText();
	}
}
